# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import traceback
import json
from django.http import JsonResponse
from utils.logger import Md_Debug
from app.manage.marketManage.common.manage_query import MarketManageDB
from app.manage.marketManage.common.manage_add_edit_delete import MarketEditeDB
from django.views.decorators.csrf import csrf_exempt
from utils.response_utils import response_change

MarketManageDB = MarketManageDB()

MarketEditeDB = MarketEditeDB()


@csrf_exempt
def market_list(request):
    """项目列表（市场运营）"""
    try:
        body = json.loads(request.body)
        data = MarketManageDB.market_list(body)
    except Exception as e:
        Md_Debug.info(traceback.format_exc(e))
        print(traceback.format_exc(e))
    response = JsonResponse(data)
    return response_change(response)


@csrf_exempt
def add_market_task(request):
    """添加项目"""
    try:
        body = json.loads(request.body)
        data = MarketEditeDB.add_market_task(body)
    except Exception as e:
        Md_Debug.info(traceback.format_exc(e))
        print(traceback.format_exc(e))
    response = JsonResponse(data)
    return response_change(response)


@csrf_exempt
def market_info(request):
    """"任务列表详情"""
    try:
        body = json.loads(request.body)
        data = MarketManageDB.market_info(body)
    except Exception as e:
        Md_Debug.info(traceback.format_exc(e))
        print(traceback.format_exc(e))
    response = JsonResponse(data)
    return response_change(response)


@csrf_exempt
def add_customer(request):
    """新增客户"""
    try:
        body = json.loads(request.body)
        data = MarketEditeDB.add_customer(body)
    except Exception as e:
        Md_Debug.info(traceback.format_exc(e))
        print(traceback.format_exc(e))
    response = JsonResponse(data)
    return response_change(response)


@csrf_exempt
def cstomer_list(request):
    """客户列表"""
    try:
        body = json.loads(request.body)
        data = MarketManageDB.cstomer_list(body)
    except Exception as e:
        Md_Debug.info(traceback.format_exc(e))
        print(traceback.format_exc(e))
    response = JsonResponse(data)
    return response_change(response)
